package registe.untill.fileUntill;

import net.iharder.Base64;

import javax.imageio.stream.FileImageOutputStream;
import java.io.*;

/**
 * Created by zhoumeineng on 2018/1/25.
 * 图片写入文件 的工具
 *
 */
public class ImageFileUntill {


    /**
     * @param path 文件路径
     * @param  images 图片 base64 字符串
     * @param fileName 图片名字
     * @param type 图片类型 ：head , face 两种类型
     * */
    public static void ImageOutput(String path,String images,String fileName,String type){

        if (images.length()==0||images==null){
            return;
        }
        File file = new File(path+"/"+type+"/"+fileName);
        FileImageOutputStream fileImageOutputStream = null;
        try {
            fileImageOutputStream = new FileImageOutputStream(file);
            fileImageOutputStream.write(Base64.decode(images));
            fileImageOutputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
            try {
                fileImageOutputStream.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }

        }

    }

}
